package com.panopset.gui.container;

import java.awt.GridLayout;
import java.awt.LayoutManager;

import javax.swing.JCheckBox;

import com.panopset.gui.LookAndFeel;
import com.panopset.java.Version;
import com.panopset.swing.App;
import com.panopset.swing.FontManager;

/**
 * JCheckBox persistent container.
 *
 * @author Karl Dinwiddie
 *
 */
public final class PanCheckBox extends PanField<JCheckBox> {

    /**
     * @param title
     *            if null, there will be no Titled Border
     * @param label
     *            Label.
     * @param toolTipText
     *            Tool tip text.
     */
    public PanCheckBox(final String title, final String label,
            final String toolTipText) {
        super(title, toolTipText, Boolean.FALSE.toString(),
                new GridLayout(1, 1));
        ((JCheckBox) getInnerComponent()).setText(label);
    }

    /**
     *
     * @param title
     *            if null, there will be no Titled Border
     * @param toolTipText
     *            Tool tip text.
     */
    public PanCheckBox(final String title, final String toolTipText) {
        super(title, toolTipText, Boolean.FALSE.toString());
    }

    /**
     * Create a Panopset checkbox with no tool tip text.
     * @param title Title.
     */
    public PanCheckBox(final String title) {
        this(title, "");
    }

    @Override
    public JCheckBox createComponent() {
        JCheckBox rtn = new JCheckBox();
        rtn.setBackground(LookAndFeel.Colors.BG_COLOR.getColor());
        App.app.fontManager.registerComponent(rtn, FontManager.FontType.plainArial);
        return rtn;
    }

    @Override
    public String getComponentValue() {
        return Boolean.valueOf(getInnerComponent().isSelected()).toString();
    }

    @Override
    public void setComponentValue(final String value) {
        getInnerComponent().setSelected(Boolean.parseBoolean(value));
    }

    /**
     * Serial version id.
     */
    private static final long serialVersionUID = Version.UNI_VERSION;

    @Override
    protected LayoutManager createLayout() {
        return new GridLayout(1, 1);
    }

    @Override
    protected boolean isValid(final String valueToCheck) {
        return true;
    }
}
